// components/scan/index.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickScan() {
      let that = this
      app.login.checkLogin().then(() => {
        app.login.checkPhone().then(() => {
          app.login.justGetUserInfo().then(res => {
            wx.scanCode({
              onlyFromCamera: true,
              success(res) {
                console.log(res)
                let q = decodeURIComponent(res.result);
                let arr = q.split("/")
                let id = parseInt(arr[arr.length - 1])
                wx.redirectTo({
                  url: '/pages/normal/myRepair/add/index?id=' + id,
                })
              },
              fail: (res) => {
                console.log(res)
              }
            })
          })
        }).catch(() => {
          wx.navigateTo({
            url: '/pages/normal/mine/login/index',
          })
        })
      }).catch(() => {
        wx.navigateTo({
          url: '/pages/normal/mine/login/index',
        })
      })
    }
  }
})